//
//  BQNavController.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/22.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

class BQNavController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        interactivePopGestureRecognizer?.delegate = self
        
    }
    
    @objc private func popClink(){
    
        self.popViewController(animated: true)
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            
            var tit:String?
            
            if childViewControllers.count == 1 {
                
                tit = self.title
                
            }
            else
            {
                tit = "返回"
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(target: self, action: #selector(popClink), imgName: "navigationbar_back_withtext", backImg: nil, title: tit)
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        
        
        return childViewControllers.count != 1
    }
    
    
    
}

/*
 
 self.navigationItem.title = "是\(self.navigationController?.childViewControllers.count ?? 0)控制器"
 
 var tit:String?
 
 
 if self.navigationController?.childViewControllers.count == 2{
 
 tit = "首页"
 
 }
 else
 {
 tit = "返回"
 }
 
 
 self.navigationItem.leftBarButtonItem = UIBarButtonItem(target: self, action: #selector(popClink), imgName: "navigationbar_back_withtext", backImg: nil, title: tit)
 
 self.navigationItem.rightBarButtonItem = UIBarButtonItem(target: self, action: #selector(pushClink), imgName: nil, backImg: nil, title: "PUSH")
 */
